<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace extend\weixin;

use WeChatPay\Crypto\Rsa;
use WeChatPay\Util\PemUtil;

/**
 * 微信配置
 * @auther clevstn
 * @since 2.0
 * @datetime 2023.11.21 11:23
 */
class WxConf
{
    //a notify domain of merchant WeChatPay.
    const MERCHANT_NOTIFY_DOMAIN = APP_NOTIFY_DOMAIN;
    //消息推送服务，消息签名token串
    const NOTIFY_TOKEN = '00000000000000000';
    //消息推送服务，消息加密key串
    const NOTIFY_BODY_KEY = '000000000000000000000000000000000000000000';
    //app id
    const APPID = 'wx0000000000000000';
    //app secret
    const APP_SECRET = '00000000000000000000000000000000';

    //APIv3 key
    const APIv3_KEY = '00000000000000000000000000000000';
    //商户号
    const MERCHANT_ID = '0000000000';
    //「商户API证书」的「证书序列号」
    const MERCHANT_CERTIFICATE_SERIAL = '0000000000000000000000000000000000000000';
    //「商户API私钥」
    const MERCHANT_PRIVATE_KEY = <<<PEM
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDhQUX8czK1vqWm
xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
tdABp/rxtxfHaZr9YvOIWfg=
-----END PRIVATE KEY-----
PEM;
    //「微信支付平台证书」的「证书序列号」
    const PLATFORM_CERTIFICATE_SERIAL = '0000000000000000000000000000000000000000';
    //「微信支付平台证书」
    const PLATFORM_CERTIFICATE = <<<PEM
-----BEGIN CERTIFICATE-----
MIIEFDCCAvygAwIBAgIUcyYiTmg/gKsKMJz+Fm6wGUCqCx8wDQYJKoZIhvcNAQEL
xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
KLBJzf5mVVLeEyTzKpbrqFSQXFRQqke9EVvKK6PcAFgpHpaTLUXK3w==
-----END CERTIFICATE-----
PEM;
    /**
     * A new instance of Merchant private key, when [self::MERCHANT_PRIVATE_KEY] is file path
     * @return mixed|resource
     * @since php8.0 (\OpenSSLAsymmetricKey)
     */
    public static function merchantPrivateKeyInstance()
    {
        return Rsa::from(self::MERCHANT_PRIVATE_KEY, Rsa::KEY_TYPE_PRIVATE);
    }

    /**
     * A new instance of WechatPay platform public key, when [self::MERCHANT_PRIVATE_KEY] is file path
     * @return mixed|resource
     * @since php8.0 (\OpenSSLAsymmetricKey)
     */
    public static function platformCertificateInstance()
    {
        return Rsa::from(self::PLATFORM_CERTIFICATE, Rsa::KEY_TYPE_PUBLIC);
    }

    /**
     * A serial number of WechatPay platform public key, when [self::MERCHANT_PRIVATE_KEY] is file path
     * @return string
     * @see self::PLATFORM_CERTIFICATE_SERIAL
     */
    public static function platformCertificateSerial()
    {
        return PemUtil::parseCertificateSerialNo(
            self::PLATFORM_CERTIFICATE
        );
    }
}